 /*
 Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
*/
using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;
using dpatoolkit;
using WeifenLuo.WinFormsUI.Docking;
using System.IO;
using BusinessLayer;
using System.Data;
using DesignPatternDefinitions;
using System.Drawing;
using dpatoolkit.UILayer;

namespace dpatoolkit.UILayer
{
	public class DPAToolkitMainForm : System.Windows.Forms.Form
	{
		#region UI Created By Visual Studio.NET
        private System.ComponentModel.IContainer components;
        private MenuStrip menuStripMain;
        private ToolStripMenuItem fileToolStripMenuItem;
        private ToolStripMenuItem newToolStripMenuItem;
        private ToolStripMenuItem projectToolStripMenuItem;
        private ToolStripMenuItem pluginToolStripMenuItem;
        private ToolStripMenuItem openToolStripMenuItem;
        private ToolStripMenuItem saveToolStripMenuItem;
        private ToolStripMenuItem exitToolStripMenuItem;
        private ToolStrip toolStrip;
        private StatusStrip statusStrip;
        private ToolStripStatusLabel statusLabel;
        private ToolStripMenuItem printToolStripMenuItem;
        private ToolStripMenuItem curCompToolStripMenuItem;
        private ToolStripMenuItem entireProjToolStripMenuItem;
        private ToolStripMenuItem viewToolStripMenuItem;
        private ToolStripMenuItem toolboxToolStripMenuItem;
        private ToolStripMenuItem projectsToolStripMenuItem;
        private ToolStripMenuItem toolsToolStripMenuItem;
        private ToolStripMenuItem addDesignPatternMenuItem;
        private ToolStripMenuItem codeGeneratorToolStripMenuItem;
        private ToolStripMenuItem reverseEngineerToolStripMenuItem;
        private ToolStripMenuItem helpToolStripMenuItem;
        private ToolStripMenuItem manualToolStripMenuItem;
        private ToolStripMenuItem aboutToolStripMenuItem;
        private ToolStripDropDownButton newToolStripButton;
        private ToolStripMenuItem projectToolStripMenuItem2;
        private ToolStripMenuItem pluginToolStripMenuItem2;
        private ToolStripButton toolStripButton2;
        private ToolStripMenuItem supportToolStripMenuItem;
        private ToolStripMenuItem askAQuestionToolStripMenuItem;
        private ToolStripMenuItem mailTToolStripMenuItem;
        private ToolStripMenuItem fromFileToolStripMenuItem;
        private ToolStripMenuItem saveAsToolStripMenuItem;
        private ToolStripMenuItem gridLinesToolStripMenuItem;
        private ToolStripMenuItem intellisenseToolStripMenuItem;
        private DockPanel dockPanel;
        private ToolStripButton toolStripDropDownButtonOpen;
        private ToolStripButton toolStripButtonSnap;
		
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() 
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DPAToolkitMainForm));
            this.menuStripMain = new System.Windows.Forms.MenuStrip();
            this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.projectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.pluginToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.curCompToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.entireProjToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolboxToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.projectsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.gridLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.intellisenseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.addDesignPatternMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.fromFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.codeGeneratorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.reverseEngineerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.manualToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.supportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.askAQuestionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mailTToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStrip = new System.Windows.Forms.ToolStrip();
            this.newToolStripButton = new System.Windows.Forms.ToolStripDropDownButton();
            this.projectToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
            this.pluginToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripDropDownButtonOpen = new System.Windows.Forms.ToolStripButton();
            this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
            this.toolStripButtonSnap = new System.Windows.Forms.ToolStripButton();
            this.statusStrip = new System.Windows.Forms.StatusStrip();
            this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel();
            this.dockPanel = new WeifenLuo.WinFormsUI.Docking.DockPanel();
            this.menuStripMain.SuspendLayout();
            this.toolStrip.SuspendLayout();
            this.statusStrip.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStripMain
            // 
            this.menuStripMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.viewToolStripMenuItem,
            this.toolsToolStripMenuItem,
            this.helpToolStripMenuItem});
            this.menuStripMain.Location = new System.Drawing.Point(0, 0);
            this.menuStripMain.Name = "menuStripMain";
            this.menuStripMain.Size = new System.Drawing.Size(800, 24);
            this.menuStripMain.TabIndex = 7;
            this.menuStripMain.Text = "menuStrip1";
            // 
            // fileToolStripMenuItem
            // 
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripMenuItem,
            this.openToolStripMenuItem,
            this.saveToolStripMenuItem,
            this.saveAsToolStripMenuItem,
            this.printToolStripMenuItem,
            this.exitToolStripMenuItem});
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
            this.fileToolStripMenuItem.Text = "&File";
            // 
            // newToolStripMenuItem
            // 
            this.newToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.projectToolStripMenuItem,
            this.pluginToolStripMenuItem});
            this.newToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("newToolStripMenuItem.Image")));
            this.newToolStripMenuItem.Name = "newToolStripMenuItem";
            this.newToolStripMenuItem.Size = new System.Drawing.Size(191, 22);
            this.newToolStripMenuItem.Text = "New";
            // 
            // projectToolStripMenuItem
            // 
            this.projectToolStripMenuItem.Name = "projectToolStripMenuItem";
            this.projectToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
            this.projectToolStripMenuItem.Text = "&Project";
            this.projectToolStripMenuItem.Click += new System.EventHandler(this.newProjMenuItem_Click);
            // 
            // pluginToolStripMenuItem
            // 
            this.pluginToolStripMenuItem.Name = "pluginToolStripMenuItem";
            this.pluginToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
            this.pluginToolStripMenuItem.Text = "&Design Pattern";
            this.pluginToolStripMenuItem.Click += new System.EventHandler(this.newPluginMenuItem_Click);
            // 
            // openToolStripMenuItem
            // 
            this.openToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("openToolStripMenuItem.Image")));
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
            this.openToolStripMenuItem.Size = new System.Drawing.Size(191, 22);
            this.openToolStripMenuItem.Text = "&Open";
            this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
            // 
            // saveToolStripMenuItem
            // 
            this.saveToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("saveToolStripMenuItem.Image")));
            this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
            this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
            this.saveToolStripMenuItem.Size = new System.Drawing.Size(191, 22);
            this.saveToolStripMenuItem.Text = "&Save";
            this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveProjMenuItem_Click);
            // 
            // saveAsToolStripMenuItem
            // 
            this.saveAsToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("saveAsToolStripMenuItem.Image")));
            this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
            this.saveAsToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
                        | System.Windows.Forms.Keys.S)));
            this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(191, 22);
            this.saveAsToolStripMenuItem.Text = "Save &All";
            this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAllToolStripMenuItem_Click);
            // 
            // printToolStripMenuItem
            // 
            this.printToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.curCompToolStripMenuItem,
            this.entireProjToolStripMenuItem});
            this.printToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("printToolStripMenuItem.Image")));
            this.printToolStripMenuItem.Name = "printToolStripMenuItem";
            this.printToolStripMenuItem.Size = new System.Drawing.Size(191, 22);
            this.printToolStripMenuItem.Text = "&Print";
            // 
            // curCompToolStripMenuItem
            // 
            this.curCompToolStripMenuItem.Name = "curCompToolStripMenuItem";
            this.curCompToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
            this.curCompToolStripMenuItem.Text = "Current Component";
            this.curCompToolStripMenuItem.Click += new System.EventHandler(this.menuItemCurCompPrint_Click);
            // 
            // entireProjToolStripMenuItem
            // 
            this.entireProjToolStripMenuItem.Name = "entireProjToolStripMenuItem";
            this.entireProjToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
            this.entireProjToolStripMenuItem.Text = "Entire Project";
            this.entireProjToolStripMenuItem.Click += new System.EventHandler(this.menuItemProjPrint_Click);
            // 
            // exitToolStripMenuItem
            // 
            this.exitToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("exitToolStripMenuItem.Image")));
            this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
            this.exitToolStripMenuItem.Size = new System.Drawing.Size(191, 22);
            this.exitToolStripMenuItem.Text = "E&xit";
            this.exitToolStripMenuItem.Click += new System.EventHandler(this.FileExitMenu_Click);
            // 
            // viewToolStripMenuItem
            // 
            this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolboxToolStripMenuItem,
            this.projectsToolStripMenuItem,
            this.gridLinesToolStripMenuItem,
            this.intellisenseToolStripMenuItem});
            this.viewToolStripMenuItem.Name = "viewToolStripMenuItem";
            this.viewToolStripMenuItem.Size = new System.Drawing.Size(41, 20);
            this.viewToolStripMenuItem.Text = "&View";
            // 
            // toolboxToolStripMenuItem
            // 
            this.toolboxToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("toolboxToolStripMenuItem.Image")));
            this.toolboxToolStripMenuItem.Name = "toolboxToolStripMenuItem";
            this.toolboxToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
                        | System.Windows.Forms.Keys.T)));
            this.toolboxToolStripMenuItem.Size = new System.Drawing.Size(192, 22);
            this.toolboxToolStripMenuItem.Text = "&Toolbox";
            this.toolboxToolStripMenuItem.Click += new System.EventHandler(this.showToolBoxMenuItem_Click);
            // 
            // projectsToolStripMenuItem
            // 
            this.projectsToolStripMenuItem.Name = "projectsToolStripMenuItem";
            this.projectsToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
                        | System.Windows.Forms.Keys.P)));
            this.projectsToolStripMenuItem.Size = new System.Drawing.Size(192, 22);
            this.projectsToolStripMenuItem.Text = "&Projects";
            this.projectsToolStripMenuItem.Click += new System.EventHandler(this.showProjsMenuItem_Click);
            // 
            // gridLinesToolStripMenuItem
            // 
            this.gridLinesToolStripMenuItem.CheckOnClick = true;
            this.gridLinesToolStripMenuItem.Name = "gridLinesToolStripMenuItem";
            this.gridLinesToolStripMenuItem.Size = new System.Drawing.Size(192, 22);
            this.gridLinesToolStripMenuItem.Text = "Grid Lines";
            this.gridLinesToolStripMenuItem.Click += new System.EventHandler(this.gridLinesToolStripMenuItem_Click);
            // 
            // intellisenseToolStripMenuItem
            // 
            this.intellisenseToolStripMenuItem.Checked = true;
            this.intellisenseToolStripMenuItem.CheckOnClick = true;
            this.intellisenseToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
            this.intellisenseToolStripMenuItem.Name = "intellisenseToolStripMenuItem";
            this.intellisenseToolStripMenuItem.Size = new System.Drawing.Size(192, 22);
            this.intellisenseToolStripMenuItem.Text = "Tooltips";
            this.intellisenseToolStripMenuItem.Click += new System.EventHandler(this.intellisenseToolStripMenuItem_Click);
            // 
            // toolsToolStripMenuItem
            // 
            this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.addDesignPatternMenuItem,
            this.codeGeneratorToolStripMenuItem,
            this.reverseEngineerToolStripMenuItem});
            this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem";
            this.toolsToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
            this.toolsToolStripMenuItem.Text = "&Tools";
            // 
            // addDesignPatternMenuItem
            // 
            this.addDesignPatternMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fromFileToolStripMenuItem});
            this.addDesignPatternMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("addDesignPatternMenuItem.Image")));
            this.addDesignPatternMenuItem.Name = "addDesignPatternMenuItem";
            this.addDesignPatternMenuItem.Size = new System.Drawing.Size(178, 22);
            this.addDesignPatternMenuItem.Text = "Add &Design Pattern";
            // 
            // fromFileToolStripMenuItem
            // 
            this.fromFileToolStripMenuItem.Name = "fromFileToolStripMenuItem";
            this.fromFileToolStripMenuItem.Size = new System.Drawing.Size(150, 22);
            this.fromFileToolStripMenuItem.Text = "Add From &File";
            // 
            // codeGeneratorToolStripMenuItem
            // 
            this.codeGeneratorToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("codeGeneratorToolStripMenuItem.Image")));
            this.codeGeneratorToolStripMenuItem.Name = "codeGeneratorToolStripMenuItem";
            this.codeGeneratorToolStripMenuItem.Size = new System.Drawing.Size(178, 22);
            this.codeGeneratorToolStripMenuItem.Text = "&Code Generators";
            this.codeGeneratorToolStripMenuItem.Click += new System.EventHandler(this.codeGenMenuItem_Click);
            // 
            // reverseEngineerToolStripMenuItem
            // 
            this.reverseEngineerToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("reverseEngineerToolStripMenuItem.Image")));
            this.reverseEngineerToolStripMenuItem.Name = "reverseEngineerToolStripMenuItem";
            this.reverseEngineerToolStripMenuItem.Size = new System.Drawing.Size(178, 22);
            this.reverseEngineerToolStripMenuItem.Text = "&Reverse Engineers";
            this.reverseEngineerToolStripMenuItem.Click += new System.EventHandler(this.revEnggMenuItem_Click);
            // 
            // helpToolStripMenuItem
            // 
            this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.manualToolStripMenuItem,
            this.supportToolStripMenuItem,
            this.aboutToolStripMenuItem});
            this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
            this.helpToolStripMenuItem.Size = new System.Drawing.Size(40, 20);
            this.helpToolStripMenuItem.Text = "Help";
            // 
            // manualToolStripMenuItem
            // 
            this.manualToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("manualToolStripMenuItem.Image")));
            this.manualToolStripMenuItem.Name = "manualToolStripMenuItem";
            this.manualToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
            this.manualToolStripMenuItem.Text = "&Manual";
            // 
            // supportToolStripMenuItem
            // 
            this.supportToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.askAQuestionToolStripMenuItem,
            this.mailTToolStripMenuItem});
            this.supportToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("supportToolStripMenuItem.Image")));
            this.supportToolStripMenuItem.Name = "supportToolStripMenuItem";
            this.supportToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
            this.supportToolStripMenuItem.Text = "&Support (Online)";
            // 
            // askAQuestionToolStripMenuItem
            // 
            this.askAQuestionToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("askAQuestionToolStripMenuItem.Image")));
            this.askAQuestionToolStripMenuItem.Name = "askAQuestionToolStripMenuItem";
            this.askAQuestionToolStripMenuItem.Size = new System.Drawing.Size(157, 22);
            this.askAQuestionToolStripMenuItem.Text = "Ask a Question";
            this.askAQuestionToolStripMenuItem.Click += new System.EventHandler(this.askAQuestionToolStripMenuItem_Click);
            // 
            // mailTToolStripMenuItem
            // 
            this.mailTToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("mailTToolStripMenuItem.Image")));
            this.mailTToolStripMenuItem.Name = "mailTToolStripMenuItem";
            this.mailTToolStripMenuItem.Size = new System.Drawing.Size(157, 22);
            this.mailTToolStripMenuItem.Text = "Mail ";
            this.mailTToolStripMenuItem.Visible = false;
            // 
            // aboutToolStripMenuItem
            // 
            this.aboutToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("aboutToolStripMenuItem.Image")));
            this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
            this.aboutToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
            this.aboutToolStripMenuItem.Text = "&About";
            this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutMenuItem_Click);
            // 
            // toolStrip
            // 
            this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripButton,
            this.toolStripDropDownButtonOpen,
            this.toolStripButton2,
            this.toolStripButtonSnap});
            this.toolStrip.Location = new System.Drawing.Point(0, 24);
            this.toolStrip.Name = "toolStrip";
            this.toolStrip.Size = new System.Drawing.Size(800, 25);
            this.toolStrip.TabIndex = 8;
            this.toolStrip.Text = "dpatoolkit toolbar";
            // 
            // newToolStripButton
            // 
            this.newToolStripButton.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.projectToolStripMenuItem2,
            this.pluginToolStripMenuItem2});
            this.newToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("newToolStripButton.Image")));
            this.newToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.newToolStripButton.Name = "newToolStripButton";
            this.newToolStripButton.Size = new System.Drawing.Size(57, 22);
            this.newToolStripButton.Text = "New";
            // 
            // projectToolStripMenuItem2
            // 
            this.projectToolStripMenuItem2.Name = "projectToolStripMenuItem2";
            this.projectToolStripMenuItem2.Size = new System.Drawing.Size(156, 22);
            this.projectToolStripMenuItem2.Text = "Project";
            this.projectToolStripMenuItem2.Click += new System.EventHandler(this.newProjMenuItem_Click);
            // 
            // pluginToolStripMenuItem2
            // 
            this.pluginToolStripMenuItem2.Name = "pluginToolStripMenuItem2";
            this.pluginToolStripMenuItem2.Size = new System.Drawing.Size(156, 22);
            this.pluginToolStripMenuItem2.Text = "Design pattern";
            this.pluginToolStripMenuItem2.Click += new System.EventHandler(this.newPluginMenuItem_Click);
            // 
            // toolStripDropDownButtonOpen
            // 
            this.toolStripDropDownButtonOpen.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButtonOpen.Image")));
            this.toolStripDropDownButtonOpen.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripDropDownButtonOpen.Name = "toolStripDropDownButtonOpen";
            this.toolStripDropDownButtonOpen.Size = new System.Drawing.Size(53, 22);
            this.toolStripDropDownButtonOpen.Text = "Open";
            this.toolStripDropDownButtonOpen.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
            // 
            // toolStripButton2
            // 
            this.toolStripButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton2.Image")));
            this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton2.Name = "toolStripButton2";
            this.toolStripButton2.Size = new System.Drawing.Size(51, 22);
            this.toolStripButton2.Text = "Save";
            this.toolStripButton2.Click += new System.EventHandler(this.saveProjMenuItem_Click);
            // 
            // toolStripButtonSnap
            // 
            this.toolStripButtonSnap.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonSnap.Image")));
            this.toolStripButtonSnap.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButtonSnap.Name = "toolStripButtonSnap";
            this.toolStripButtonSnap.Size = new System.Drawing.Size(72, 22);
            this.toolStripButtonSnap.Text = "Snapshot";
            this.toolStripButtonSnap.Click += new System.EventHandler(this.toolStripButtonSnap_Click);
            // 
            // statusStrip
            // 
            this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.statusLabel});
            this.statusStrip.Location = new System.Drawing.Point(0, 579);
            this.statusStrip.Name = "statusStrip";
            this.statusStrip.Size = new System.Drawing.Size(800, 22);
            this.statusStrip.TabIndex = 11;
            // 
            // statusLabel
            // 
            this.statusLabel.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.statusLabel.Image = ((System.Drawing.Image)(resources.GetObject("statusLabel.Image")));
            this.statusLabel.Name = "statusLabel";
            this.statusLabel.Size = new System.Drawing.Size(38, 17);
            this.statusLabel.Text = "Ready";
            // 
            // dockPanel
            // 
            this.dockPanel.ActiveAutoHideContent = null;
            this.dockPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dockPanel.DockBottomPortion = 0.12;
            this.dockPanel.DockLeftPortion = 0.12;
            this.dockPanel.DockRightPortion = 0.12;
            this.dockPanel.DockTopPortion = 0.12;
            this.dockPanel.Font = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
            this.dockPanel.Location = new System.Drawing.Point(0, 49);
            this.dockPanel.Name = "dockPanel";
            this.dockPanel.Size = new System.Drawing.Size(800, 530);
            this.dockPanel.TabIndex = 18;
            // 
            // DPAToolkitMainForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(800, 601);
            this.Controls.Add(this.dockPanel);
            this.Controls.Add(this.statusStrip);
            this.Controls.Add(this.toolStrip);
            this.Controls.Add(this.menuStripMain);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.IsMdiContainer = true;
            this.KeyPreview = true;
            this.MainMenuStrip = this.menuStripMain;
            this.Name = "DPAToolkitMainForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Design Pattern Automation Toolkit";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Closing += new System.ComponentModel.CancelEventHandler(this.DesignPatternApplicationForm_Closing);
            this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.DPAToolkitMainForm_KeyPress);
            this.menuStripMain.ResumeLayout(false);
            this.menuStripMain.PerformLayout();
            this.toolStrip.ResumeLayout(false);
            this.toolStrip.PerformLayout();
            this.statusStrip.ResumeLayout(false);
            this.statusStrip.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion
		
		#endregion

		#region Constructor , Initializers
		public DPAToolkitMainForm()
		{
			try
			{
				InitializeComponent();
                InitDPMenu();

                DPAppData.MDIManager.StatusBar = this.statusLabel;
                DPAppData.MDIManager.DockPanel = this.dockPanel;
                DPAppData.MDIManager.ShowToolbox(true);
                DPAppData.MDIManager.ShowProjectTreeView(true);
			}
			catch(Exception e)
			{
				ErrorMessage.Show("Encountered the following error during start up \n "+e.ToString(),"plase Take a snapshot of this and please report a bug");
			}
		}

		#endregion
			
		#region EventHandlers
		
		private void DesignPatternApplicationForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			this.SaveAll(true /* ask for user confirmation when closing */);
		}
		#endregion
		
		#region Implementation Functions

		public void SaveAll(bool confirm)
		{
            DPAppData.ProjectManager.SaveAll(confirm);
		}

		public void ActivateComponent(Form form)
		{
			if( form==null)
				return;
			this.ActivateMdiChild(form);
			form.Activate();
		}

		#endregion			
			
		#region Initialization
		
		private void InitDPMenu()
		{
			try
			{
				MenuItem[] items = dpatoolkit.GlobalFactory.CreateDesignPatternMenuItems();
				foreach (MenuItem item in items)
				{
                    ToolStripMenuItem menuItem = new ToolStripMenuItem(item.Text);
                    this.addDesignPatternMenuItem.DropDownItems.Add(menuItem);
					
					foreach(MenuItem dpMenuItem in item.MenuItems)
					{
                        ToolStripMenuItem subMenuItem = new ToolStripMenuItem(dpMenuItem.Text);
                        subMenuItem.Click += new EventHandler(this.dpMenuItem_Click);
                        subMenuItem.Tag = menuItem.Text; // the tag contains the category.
                        menuItem.DropDownItems.Add(subMenuItem);
					}
				}
			}
			catch(Exception e)
			{
				ErrorMessage.Show("Error while constructing the design pattern menu! Details:"+e.ToString()); 
			}
		}
		#endregion
		
		#region Event Handlers
        /// <summary>
        /// Create a Design Pattern Plugin
        /// </summary>
		private void newPluginMenuItem_Click(object sender, System.EventArgs e)
		{
            DPAppData.ProjectManager.GetProject(ProjectType.DesignPatternPlugin);
		}
        
		private void newProjMenuItem_Click(object sender, System.EventArgs e)
		{
            DPAppData.ProjectManager.GetProject(ProjectType.Project);
		}
		private void saveProjMenuItem_Click(object sender, System.EventArgs e)
		{
            IMdiChild child = DPAppData.MDIManager.CurrentDocument;
            if (child != null)
            {
                IUIProjectUnit proj = child.Project;
                proj.Save(false);
                return;
            }
		}

        private void openToolStripMenuItem_Click(object sender, System.EventArgs e)
		{
            //now read the new project
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.DereferenceLinks = true;
            dialog.Title = "Open Project / Design Pattern plugin";
            dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            dialog.FilterIndex = 1; // select xml
            if (dialog.ShowDialog() == DialogResult.Cancel)
                return;
            DPAppData.ProjectManager.GetProject(dialog.FileName);
		}
		private void showToolBoxMenuItem_Click(object sender, System.EventArgs e)
		{
			DPAppData.MDIManager.ShowToolbox(true);
		}
		private void showProjsMenuItem_Click(object sender, System.EventArgs e)
		{
			DPAppData.MDIManager.ShowProjectTreeView(true);
		}
		private void FileExitMenu_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		private void ArrangeCascadeMenu_Click(object sender, System.EventArgs e)
		{
			LayoutMdi(MdiLayout.Cascade);
		}
		private void ArrangeVertMenu_Click(object sender, System.EventArgs e) 
		{
			LayoutMdi(MdiLayout.TileVertical);
		}
		private void ArrangeHorizontalMenu_Click(object sender, System.EventArgs e) 
		{
			LayoutMdi(MdiLayout.TileHorizontal);
		}

		private void dpMenuItem_Click(object sender, EventArgs e)
		{
			IMdiChild child = DPAppData.MDIManager.CurrentDocument;
			if(child == null)
			{
                ErrorMessage.Show("No Class Diagrams found to add the design pattern.");
				return;
			}

            ToolStripMenuItem item = sender as ToolStripMenuItem;
			if(item == null)
				return;
			string category = item.Tag as string;
			string dpname = item.Text;
			string pathToDP = dpatoolkit.GlobalFactory.ConstructPathToPattern(category,dpname);
			child.MergePattern(pathToDP);
		}
		private void AddDPFromFile_Click(object sender, EventArgs e)
		{
			IMdiChild child = DPAppData.MDIManager.CurrentDocument;
			if(child == null)
			{
				ErrorMessage.Show("No Class Diagrams found to add the design pattern.");
				return;
			}
			child.MergePattern(string.Empty);
		}
		private void codeGenMenuItem_Click(object sender, System.EventArgs e)
		{
			CodeGenPluginForm form = new CodeGenPluginForm();
			form.ShowDialog();
		}
		private void revEnggMenuItem_Click(object sender, System.EventArgs e)
		{
			try
			{
				ReverseEnggPluginForm revEngForm = new ReverseEnggPluginForm();
				revEngForm.ShowDialog(this);
				if( revEngForm.DialogResult== DialogResult.Cancel)
					return;
				IReverseEngineer revEngg =  revEngForm.ReverseEngineer;
				if( revEngg==null) return;
				
				IProject proj = revEngg.GetProject();
				if(proj!=null)
				{
                    DPAppData.ProjectManager.GetProject(proj);
				}
				else
					return;
			}
			catch( Exception exp)
			{
				ErrorMessage.Show("Error in Rev Engg Menu Handler::\n"+exp.ToString(),"Error");
				MessageBox.Show("always use the latest plugins provided in the samples directory");
			}
		}

		private void helpMenuItem_Click(object sender, System.EventArgs e)
		{
			try
			{
				System.Diagnostics.Process.Start(GlobalSettings.HtmlHelpLink);
			}
			catch(Exception exp)
			{
				ErrorMessage.Show(@"sorry couldnot launch the browser, the docs are present under " + GlobalSettings.HtmlHelpLink,
						"error,"+exp.Message);
			}
		}

		private void aboutMenuItem_Click(object sender, System.EventArgs e)
		{
			new SplashScreen(SplashScreen.Mode.About).ShowDialog();
		}

        private void toolStripButtonSnap_Click(object sender, EventArgs e)
        {
            IMdiChild curComp = DPAppData.MDIManager.CurrentDocument;

            if (curComp == null)
            {
                DPAppData.MDIManager.ShowStatusMessage("No Document open for snapshot generation", 5000);
                return;
            }
            SaveFileDialog dialog = new SaveFileDialog();
            if (dialog.ShowDialog() == DialogResult.Cancel)
                return;
            curComp.SaveAsImage(dialog.FileName);//ask the component generate the image

        }
		
		private void menuItemCurCompPrint_Click(object sender, System.EventArgs e)
		{
		
			IMdiChild child = DPAppData.MDIManager.CurrentDocument;
			if(child == null)
			{
				ErrorMessage.Show("No components/plugins found to print!");
				return;
			}
			child.Print();
		}

		private void menuItemProjPrint_Click(object sender, System.EventArgs e)
		{
            IUIProjectUnit projMan = null; // DPAppData.GetProjectManager("to Print");
			if(projMan==null)
			{
				MessageBox.Show("No Projects found to print! \n open a proj or create a new one!");
				return;
			}
			projMan.Command(MdiCommand.PrintAllComponents);
		}

        private void saveAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DPAppData.ProjectManager.SaveAll(false);
        }

        private void gridLinesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem gridLineItem = sender as ToolStripMenuItem;
            UIRenderer.EnableGridLines = gridLineItem.Checked;
        }

        private void intellisenseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem inteliItem = sender as ToolStripMenuItem;
            GlobalSettings.EnableIntellisense = inteliItem.Checked;
        }

        private void askAQuestionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start("http://sourceforge.net/forum/forum.php?forum_id=424619");
            }
            catch
            {
            }
        }

        private void DPAToolkitMainForm_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Escape)
            {
                DPAppData.ResetState();
            }
        }
        #endregion

        

    }
}

